/// <summary>
/// Colour object.
/// </summary>
public class Colour
{
    /// <summary>
    /// _RGB values for this.ColourByte
    /// </summary>
    public int[] RGB;

    /// <summary>
    /// //Byte representing RBG values
    /// </summary>
    public byte[] ColourByte { get; private set; }

    /// <summary>
    /// Colour Constructor
    /// </summary>
    /// <param name="r">Red Value</param>
    /// <param name="g">Green Value</param>
    /// <param name="b">Blue Value</param>
    public Colour(int r, int g, int b)
    {
        if (r > 255)
            r = 255;
        else if (r < 0)
            r = 0;

        if (g > 255)
            g = 255;
        else if (g < 0)
            g = 0;

        if (b > 255)
            b = 255;
        else if (b < 0)
            b = 0;

        this.RGB = new int[] { r, g, b };

        int temp = (((RGB[0] >> 3) << 11) | ((RGB[1] >> 2) << 5) | (RGB[2] >> 3));

        if(this.ColourByte == null)
             this.ColourByte = new byte[2];

        this.ColourByte[0] = (byte)(temp >> 8);
        this.ColourByte[1] = (byte)(temp & 0x00FF);
    }

    public Colour(byte[] colour)
    {
        int temp = (((colour[0] >> 2) |  192) << 8) | ((colour[1] >> 1) | 2);

        int r = (byte)(((temp >> 11) & 0x1F) << 3);

        int g = (byte)(((temp >> 5) & 63) << 2);

        int b = (byte)(((temp & 0x1F) << 0x03));

        this.RGB = new int[] { r, g, b };
        this.ColourByte = colour;
    }
    /// <summary>
    /// Return a string representing this object
    /// </summary>
    /// <returns>string</returns>
    public override string ToString()
    {
        return "(" + this.RGB[0] + ", " + this.RGB[1] + ", " + this.RGB[2] + ")";
    }
}